set more off
**cd "/Users/cason/Dropbox/Research/Gender_groups/data"
cd "C:\Users\cason\Dropbox\Research\Gender_groups\data\data2021\"
** Check some key summary info **

** First what are the choices by gender for the Part 2 allocation tasks **
use subPart2_13sess.dta

keep if type<2
gen FemaleID=gender-1
gen BornHalf1 = 0
replace BornHalf1 = 1 if season < 2.5

** Here are the Part 2 allocation choices, where 1 earns 7 and 2 earns 5 for Type C **
** Create an ID variable = 1 if choice 2 is selected **
** Choice 2 is always the kinder choice **
gen Choice2ID = typeCInput-1
gen Part2Kind = Choice2ID

** Start of Section 4.1 **
table FemaleID Choice2ID
tabulate FemaleID, summarize(Part2Kind) nostandard
tabulate sessnum, summarize(Part2Kind) nostandard

xtset sessnum
xtreg Part2Kind FemaleID, re

gen subsess=sessnum+Subject

sort subsess

***save Part2Kind.dta, replace

clear

** Next look at the choices in the coordination game of Part 1 **
use subPart1_13sess.dta

** How many OTHER women are in the group of 2 other Type Cs **

gen numOtherFem=genderC1+genderC2-2

** Create a gender ID variable *

gen FemaleID=gender-1

** Create an ID variable = 1 if choice 2 is selected **
gen Choice2ID = typeCAction - 1
** Choice 2 is always the kinder choice **

** Here are the unconditional choices, where 1 earns 7 and 2 earns 5 for Type C **

table Choice2ID
table Choice2ID FemaleID
** Combine these session averages with the Allocation choice (Part 2) session averages for Figure 1 **
tabulate sessnum, summarize(Choice2ID) nostandard

** Now condition on the number of other women in the group when info about gender is provided *

** Adding in the no info case by making numOtherFem missing denoted -1 from subjects perspective *
replace numOtherFem=-1 if infoProvided==0

table Choice2ID numOtherFem
tabulate numOtherFem, summarize(Choice2ID) nostandard

gen subsess=sessnum+Subject

sort subsess

merge m:1 subsess using Part2Kind.dta

drop _merge

** Now merge in the demographic characteristics **

merge m:1 subsess using risk_prefs_survey21.dta

keep if type<2

drop _merge

** correlation of ave part 1 kindness and part 2 dictator **
tabulate Part2Kind, summarize(Choice2ID) nostandard

** Organize the data to analyze as group choice, not individual vote **
sort sessnum Period Group Subject
gen groupEnd=0
replace groupEnd=1 if Group!=Group[_n+1]
** groupEnd defined above is the 3rd in the group, use to collect group info **
gen numFem = FemaleID + FemaleID[_n-1] + FemaleID[_n-2] if groupEnd==1
gen majFem = 0 if groupEnd==1
replace majFem = 1 if numFem > 1.5 & groupEnd==1
gen numPt2Kind = Part2Kind + Part2Kind[_n-1] + Part2Kind[_n-2] if groupEnd==1

gen numKind = Choice2ID + Choice2ID[_n-1] + Choice2ID[_n-2] if groupEnd==1

** Compilation of demographic controls at the group level **
gen frac_least_averse = (least_averse + least_averse[_n-1] + least_averse[_n-2])/3 if groupEnd==1
gen frac_BusEcon = (BusEconID + BusEconID[_n-1] + BusEconID[_n-2])/3 if groupEnd==1
gen frac_EngSci = (EngSciID + EngSciID[_n-1] + EngSciID[_n-2])/3 if groupEnd==1
gen frac_bornNotUS = (bornNotUS + bornNotUS[_n-1] + bornNotUS[_n-2])/3 if groupEnd==1

gen frac_asian = (asianID + asianID[_n-1] + asianID[_n-2])/3 if groupEnd==1
gen frac_blackHisp = (blackHispID + blackHispID[_n-1] + blackHispID[_n-2])/3 if groupEnd==1
gen nonWhiteHisp = asianID + blackHispID
gen frac_nonWhiteHisp = (nonWhiteHisp + nonWhiteHisp[_n-1] + nonWhiteHisp[_n-2])/3 if groupEnd==1

gen frac_religion = (religionID + religionID[_n-1] + religionID[_n-2])/3 if groupEnd==1
gen frac_HighGPA = (HighGPAID + HighGPAID[_n-1] + HighGPAID[_n-2])/3 if groupEnd==1
gen frac_freshsoph = (freshsophID + freshsophID[_n-1] + freshsophID[_n-2])/3 if groupEnd==1

** Data for Figures 2, 3 and 4 **
table numKind numFem
table numKind majFem
table numKind numPt2Kind
table numKind numPt2Kind if majFem < 0.5
table numKind numPt2Kind if majFem > 0.5

tabulate numFem, summarize(numKind) nostandard
tabulate majFem, summarize(numKind) nostandard
tabulate numPt2Kind, summarize(numKind) nostandard

** Table 3 regressions for group outcomes **
gen MgroupKind = 0 if numKind<1.5 & groupEnd==1
replace MgroupKind = 1 if numKind>1.5 & groupEnd==1
** This uses the majority vote for the 20 out of 624 cases of miscoordination **

** Table 3 in the paper **

xtreg MgroupKind numFem if payoffCase==1, re
outreg2 using DcoordRegs.xls, replace ctitle(Number Women) 10pct

xtreg MgroupKind numFem numPt2Kind if payoffCase==1, re
outreg2 using DcoordRegs.xls, append ctitle(Number Women) 10pct

xtreg MgroupKind numFem numPt2Kind infoProvided Period frac_least_averse frac_BusEcon frac_EngSci frac_bornNotUS frac_nonWhiteHisp frac_religion frac_HighGPA frac_freshsoph if payoffCase==1, re
outreg2 using DcoordRegs.xls, append ctitle(Number Women) 10pct
test frac_least_averse frac_BusEcon frac_EngSci frac_bornNotUS frac_nonWhiteHisp frac_religion frac_HighGPA frac_freshsoph 

** Now about majority vs. minority women in the group **
xtreg MgroupKind majFem if payoffCase==1, re
outreg2 using DcoordRegs.xls, append ctitle(Majority Women) 10pct

xtreg MgroupKind majFem numPt2Kind if payoffCase==1, re
outreg2 using DcoordRegs.xls, append ctitle(Majority Women) 10pct

xtreg MgroupKind majFem numPt2Kind infoProvided Period frac_least_averse frac_BusEcon frac_EngSci frac_bornNotUS frac_nonWhiteHisp frac_religion frac_HighGPA frac_freshsoph if payoffCase==1, re
outreg2 using DcoordRegs.xls, append ctitle(Majority Women) 10pct
test frac_least_averse frac_BusEcon frac_EngSci frac_bornNotUS frac_nonWhiteHisp frac_religion frac_HighGPA frac_freshsoph 

xtreg MgroupKind FemaleID if payoffCase==1 & (numFem==3 | numFem==0), re
outreg2 using DcoordRegs.xls, append ctitle(Uniform Gender) 10pct

xtreg MgroupKind FemaleID numPt2Kind if payoffCase==1 & (numFem==3 | numFem==0), re
outreg2 using DcoordRegs.xls, append ctitle(Uniform Gender) 10pct

xtreg MgroupKind FemaleID numPt2Kind infoProvided Period frac_least_averse frac_BusEcon frac_EngSci frac_bornNotUS frac_nonWhiteHisp frac_religion frac_HighGPA frac_freshsoph if payoffCase==1 & (numFem==3 | numFem==0), re
outreg2 using DcoordRegs.xls, append ctitle(Uniform Gender) 10pct
test frac_least_averse frac_BusEcon frac_EngSci frac_bornNotUS frac_nonWhiteHisp frac_religion frac_HighGPA frac_freshsoph 


** Repeat but for only the cases with gender info provided : Appendix Table B-3 **

xtreg MgroupKind numFem if payoffCase==1 & infoProvided>0, re
outreg2 using NIcoordRegs.xls, replace ctitle(Number Women) 10pct

xtreg MgroupKind numFem numPt2Kind if payoffCase==1 & infoProvided>0, re
outreg2 using NIcoordRegs.xls, append ctitle(Number Women) 10pct

xtreg MgroupKind numFem numPt2Kind Period frac_least_averse frac_BusEcon frac_EngSci frac_bornNotUS frac_nonWhiteHisp frac_religion frac_HighGPA frac_freshsoph if payoffCase==1 & infoProvided>0, re
outreg2 using NIcoordRegs.xls, append ctitle(Number Women) 10pct

** Now about majority vs. minority women in the group **
xtreg MgroupKind majFem if payoffCase==1 & infoProvided>0, re
outreg2 using NIcoordRegs.xls, append ctitle(Majority Women) 10pct

xtreg MgroupKind majFem numPt2Kind if payoffCase==1 & infoProvided>0, re
outreg2 using NIcoordRegs.xls, append ctitle(Majority Women) 10pct

xtreg MgroupKind majFem numPt2Kind Period frac_least_averse frac_BusEcon frac_EngSci frac_bornNotUS frac_nonWhiteHisp frac_religion frac_HighGPA frac_freshsoph if payoffCase==1 & infoProvided>0, re
outreg2 using NIcoordRegs.xls, append ctitle(Majority Women) 10pct

xtreg MgroupKind FemaleID if payoffCase==1 & (numFem==3 | numFem==0) & infoProvided>0, re
outreg2 using NIcoordRegs.xls, append ctitle(Uniform Gender) 10pct

xtreg MgroupKind FemaleID numPt2Kind if payoffCase==1 & (numFem==3 | numFem==0) & infoProvided>0, re
outreg2 using NIcoordRegs.xls, append ctitle(Uniform Gender) 10pct

xtreg MgroupKind FemaleID numPt2Kind Period frac_least_averse frac_BusEcon frac_EngSci frac_bornNotUS frac_nonWhiteHisp frac_religion frac_HighGPA frac_freshsoph if payoffCase==1 & (numFem==3 | numFem==0) & infoProvided>0, re
outreg2 using NIcoordRegs.xls, append ctitle(Uniform Gender) 10pct


** Repeat but for all data but with logit specification : Appendix Table B-2 **

xtlogit MgroupKind numFem if payoffCase==1, re
outreg2 using LcoordRegs.xls, replace ctitle(Number Women) 10pct

xtlogit MgroupKind numFem numPt2Kind if payoffCase==1, re
outreg2 using LcoordRegs.xls, append ctitle(Number Women) 10pct

xtlogit MgroupKind numFem numPt2Kind infoProvided Period frac_least_averse frac_BusEcon frac_EngSci frac_bornNotUS frac_nonWhiteHisp frac_religion frac_HighGPA frac_freshsoph if payoffCase==1, re
outreg2 using LcoordRegs.xls, append ctitle(Number Women) 10pct

** Now about majority vs. minority women in the group **
xtlogit MgroupKind majFem if payoffCase==1, re
outreg2 using LcoordRegs.xls, append ctitle(Majority Women) 10pct

xtlogit MgroupKind majFem numPt2Kind if payoffCase==1, re
outreg2 using LcoordRegs.xls, append ctitle(Majority Women) 10pct

xtlogit MgroupKind majFem numPt2Kind infoProvided Period frac_least_averse frac_BusEcon frac_EngSci frac_bornNotUS frac_nonWhiteHisp frac_religion frac_HighGPA frac_freshsoph if payoffCase==1, re
outreg2 using LcoordRegs.xls, append ctitle(Majority Women) 10pct

xtlogit MgroupKind FemaleID if payoffCase==1 & (numFem==3 | numFem==0), re
outreg2 using LcoordRegs.xls, append ctitle(Uniform Gender) 10pct

xtlogit MgroupKind FemaleID numPt2Kind if payoffCase==1 & (numFem==3 | numFem==0), re
outreg2 using LcoordRegs.xls, append ctitle(Uniform Gender) 10pct

xtlogit MgroupKind FemaleID numPt2Kind infoProvided Period frac_least_averse frac_BusEcon frac_EngSci frac_bornNotUS frac_nonWhiteHisp frac_religion frac_HighGPA frac_freshsoph if payoffCase==1 & (numFem==3 | numFem==0), re
outreg2 using LcoordRegs.xls, append ctitle(Uniform Gender) 10pct


** Placebo tests for being born in the first half of the year : Appendix Table B-4 **

sort sessnum Period Group Subject
gen numBornHalf1 = BornHalf1 + BornHalf1[_n-1] + BornHalf1[_n-2] if groupEnd==1
gen majBornHalf1 = 0 if groupEnd==1
replace majBornHalf1 = 1 if numBornHalf1 > 1.5 & groupEnd==1

xtreg MgroupKind numBornHalf1 numPt2Kind if payoffCase==1, re
outreg2 using BH1coordRegs.xls, replace ctitle(Number Early) 10pct

xtreg MgroupKind numBornHalf1 numPt2Kind infoProvided Period frac_least_averse frac_BusEcon frac_EngSci frac_bornNotUS frac_nonWhiteHisp frac_religion frac_HighGPA frac_freshsoph if payoffCase==1, re
outreg2 using BH1coordRegs.xls, append ctitle(Number Early) 10pct

** Now about majority vs. minority born in half 1 in the group **

xtreg MgroupKind majBornHalf1 numPt2Kind if payoffCase==1, re
outreg2 using BH1coordRegs.xls, append ctitle(Majority Early) 10pct

xtreg MgroupKind majBornHalf1 numPt2Kind infoProvided Period frac_least_averse frac_BusEcon frac_EngSci frac_bornNotUS frac_nonWhiteHisp frac_religion frac_HighGPA frac_freshsoph if payoffCase==1, re
outreg2 using BH1coordRegs.xls, append ctitle(Majority Early) 10pct

xtreg MgroupKind BornHalf1 numPt2Kind if payoffCase==1 & (numBornHalf1==3 | numBornHalf1==0), re
outreg2 using BH1coordRegs.xls, append ctitle(Uniform Early) 10pct

xtreg MgroupKind BornHalf1 numPt2Kind infoProvided Period frac_least_averse frac_BusEcon frac_EngSci frac_bornNotUS frac_nonWhiteHisp frac_religion frac_HighGPA frac_freshsoph if payoffCase==1 & (numBornHalf1==3 | numBornHalf1==0), re
outreg2 using BH1coordRegs.xls, append ctitle(Uniform Early) 10pct


** How often subjects make different decisions across rounds--end of Section 4.2 **
collapse (mean) Choice2ID, by(Part2Kind sessnum subsess FemaleID)

** Consistency is closest to 0 and 1 in average Choice2ID rate, 0.5 is least consistent **
gen consistent = abs(0.5-Choice2ID)
** Highest score on consistent is most consistent (ranges 0 to 0.5) **
sum consistent 
by FemaleID, sort : summarize consistent 
by Part2Kind, sort : summarize consistent 
xtreg consistent FemaleID Part2Kind, re
** above regression shows that women are marginally less consistent than men **




